members = ['Mike', 'Ellie', 'Rohan', 'Fatma']
bikes = ['红', '紫', '蓝', '绿']
ranks = [1, 2, 3, 4]

states = []  # 所有可能的状态
for rank in ranks:
    for member in members:
        for bike in bikes:
            states.append((rank, member, bike))

impossible_states = []  # 不可能状态
for state in states:
    rank, member, bike = state[0], state[1], state[2]
    if (member == 'Ellie' and bike != '紫') or (bike == '紫' and member != 'Ellie'):  # Ellie没有骑紫色的车
        impossible_states.append(state)
        continue
    if member == 'Rohan' and bike == '绿':  # Rohan骑了绿色的车
        impossible_states.append(state)
        continue
    if (member == 'Mike' or member == 'Ellie') and (rank == 1 or rank == 4):  # Mike或者Ellie是第一或最后
        impossible_states.append(state)

possible_states = []
for state in states:
    if state not in impossible_states:
        possible_states.append(state)

rank1 = []
rank2 = []
rank3 = []
rank4 = []
for state in possible_states:
    rank = state[0]
    if rank == 1:
        rank1.append(state)
    if rank == 2:
        rank2.append(state)
    if rank == 3:
        rank3.append(state)
    if rank == 4:
        rank4.append(state)

possible_result = []
for r1 in rank1:
    for r2 in rank2:
        for r3 in rank3:
            for r4 in rank4:
                if r1[1] != r2[1] and r1[1] != r3[1] and r1[1] != r4[1] and r2[1] != r3[1] and r2[1] != r4[1] \
                        and r3[1] != r4[1] and r1[2] != r2[2] and r1[2] != r3[2] and r1[2] != r4[2] and r2[2] != r3[2] \
                        and r2[2] != r4[2] and r3[2] != r4[2]:
                    possible_result.append([r1, r2, r3, r4])

impossible_result = []  # 不可能结果
for state in possible_result:
    green_flag = 0
    blue_flag = 0
    for each in state:
        if each[2] == '紫' and green_flag == 0:  # 紫色车领先绿色车
            impossible_result.append(state)
        if each[1] == 'Fatma' and blue_flag == 0:  # Fatma领先蓝色车
            impossible_result.append(state)
        if each[2] == '绿':
            green_flag = 1
        if each[2] == '蓝':
            blue_flag = 1

result = []
for each in possible_result:
    if each not in impossible_result:
        result.append(each)

for each in result:
    print(each)
